/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.entities;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.Lob;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToOne;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author ben
 */
@Entity
@Table(name="credit")
@NamedQueries({
    @NamedQuery(name = "Credit.findAll", query = "SELECT r FROM Credit r"),
    @NamedQuery(name = "Credit.findByCompanyDenomination", query="SELECT r FROM Credit r  WHERE r.used = FALSE AND r.companyDenomination = :companyDenomination "),
    @NamedQuery(name = "Credit.findById", query = "SELECT r FROM Credit r WHERE r.id = :id"),
})
public class Credit implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    
    private String encodedText;
    private Boolean used = Boolean.FALSE;
    private String pin;
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateCreated = new Date();
    @Temporal(TemporalType.TIMESTAMP)
    private Date dateUsed;
    private String fileName;

    public String getFileName() {
        return fileName;
    }

    public void setFileName(String fileName) {
        this.fileName = fileName;
    }
    
    @OneToOne(mappedBy = "credit", cascade = CascadeType.ALL)
    private Transactions transactions;

    public Transactions getTransactions() {
        return transactions;
    }

    public void setTransactions(Transactions transactions) {
        this.transactions = transactions;
    }
    
    
    
   @ManyToOne
    private CompanyDenomination companyDenomination;

    public CompanyDenomination getCompanyDenomination() {
        return companyDenomination;
    }

     //Image Column
    @Lob
    private byte[] image;

    public byte[] getImage() {
        return image;
    }

    public void setImage(byte[] image) {
        this.image = image;
    }
    
    
    
    public void setCompanyDenomination(CompanyDenomination companyDenomination) {
        this.companyDenomination = companyDenomination;
    }
   
   

    public Date getDateCreated() {
        return dateCreated;
    }

    public void setDateCreated(Date dateCreated) {
        this.dateCreated = dateCreated;
    }

    public Date getDateUsed() {
        return dateUsed;
    }

    public void setDateUsed(Date dateUsed) {
        this.dateUsed = dateUsed;
    }
    
    

    public String getEncodedText() {
        return encodedText;
    }

    public void setEncodedText(String encodedText) {
        this.encodedText = encodedText;
    }

    public Boolean getUsed() {
        return used;
    }

    public void setUsed(Boolean used) {
        this.used = used;
    }

    public String getPin() {
        return pin;
    }

    public void setPin(String pin) {
        this.pin = pin;
    }
    
  
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Credit)) {
            return false;
        }
        Credit other = (Credit) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "com.entities.Credit[ id=" + id + " ]";
    }
    
}
